package com.o2o.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * package_name:com.o2o.utils
 * Author:徐亚远
 * Date:2019/11/28 13:33
 * 项目名:o2o
 * Desription:
 **/
@Configuration
public class PathUtil {
    private static String seperator = System.getProperty("file.separator");
    private static String winPath;

    private static String linuxPath;

    private static String shopPath;

    @Value("${win.base.path}")
    public  void setWinPath(String winPath) {
        PathUtil.winPath = winPath;
    }
    @Value("${linux.base.path}")
    public  void setLinuxPath(String linuxPath) {
        PathUtil.linuxPath = linuxPath;
    }
    @Value("${shop.relevant.path}")
    public  void setShopPath(String shopPath) {
        PathUtil.shopPath = shopPath;
    }

    public static String getImageBasePath(){
        String os = System.getenv("os.name");
        String basePath="";
        if(os.toLowerCase().startsWith("win")){
            basePath=winPath;
        }else {
            basePath=linuxPath;
        }
           basePath=basePath.replace("/",seperator );
        return basePath;
    }
    public static String getShopImagePath(long shopId){
        String imagePath = shopPath+shopId+seperator;
        return imagePath.replace("/",seperator );
    }
}
